package com.zy.composeworld.base

import android.content.Context
import android.content.Intent
import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.graphics.Paint
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment


class MainContainerActivity : BaseMainActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        //是否黑白显示
        if (false) {
            val mPaint = Paint()
            val cm = ColorMatrix()
            cm.setSaturation(0F)
            mPaint.colorFilter = ColorMatrixColorFilter(cm)
            window.decorView.setLayerType(View.LAYER_TYPE_SOFTWARE, mPaint)
        }
    }

    override fun isImmersion(): Boolean = true

    override fun lightMode(): Boolean = true

    companion object {
        fun start(context: Context, fragmentClass: Class<out Fragment>) {
            context.startActivity(Intent(context, MainContainerActivity::class.java).apply {
                putExtra("targetClass", fragmentClass)
            })
        }
    }

    override fun onResume() {
        super.onResume()
        //overridePendingTransition()
    }

    override fun onDestroy() {
        super.onDestroy()
    }

    override val containerFragment: Fragment?
        get() {
            val targetClass = intent.getSerializableExtra("targetClass") as Class<*>?
            var fragment: Fragment? = null
            if (targetClass != null) {
                try {
                    fragment = targetClass.newInstance() as Fragment
                } catch (e: IllegalAccessException) {
                    e.printStackTrace()
                } catch (e: InstantiationException) {
                    e.printStackTrace()
                }
            }

            return fragment
        }
}